<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script>
    // document.getElementById('demo').onclick = function () {
    //   console.log('被单击了');
    // };
    window.onload = function () {
      document.getElementById('demo').onclick = function () {
        console.log('被单击了');
      };
    };
  </script>
  <div id="demo">测试</div>  
</body>
</html>